package meituan;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class test01 {
    static class  Node{
        int val;
        int num;
        Node(int val,int num){
            this.val = val;
            this.num = num;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(sc.readLine());
        Map<Integer,Integer> map = new HashMap<>();//用来存储数据
        Queue<Node> p = new PriorityQueue<>(10,new Comparator<Node>() {
            @Override
            public int compare(Node o1, Node o2) {
                return -(o1.num-o2.num);
            }
        }) ;//建立一个堆用来保存节点数据
        ArrayList<String> arr = new ArrayList<>();//保存每一行的数据
        for (int i = 0; i < n; i++) {
            arr.add(sc.readLine());
        }
        for (String str:arr) {
            String[] s = str.split(" ");
            if(s[0].equals("query")){
                if(map.isEmpty()){
                    System.out.println("null");
                }else{
                    StringBuilder temp = new StringBuilder();
                    for(Map.Entry<Integer,Integer> entry:map.entrySet()){
                        Node node = new Node(entry.getKey(),entry.getValue());
                        p.add(node);
                    }
                    while(!p.isEmpty() ){
                        Node poll = p.poll();
                        temp.append(poll.val).append(" ");
                    }
                    System.out.println(temp.toString());
                }
            }else{
                if(map.containsKey(Integer.parseInt(s[1]))){
                    map.put(Integer.parseInt(s[1]),map.get(Integer.parseInt(s[1]))+Integer.parseInt(s[2]));
                }else{
                    map.put(Integer.parseInt(s[1]),Integer.parseInt(s[2]));
                }
            }
        }
    }
}
